// 显示重置密码弹窗
function showResetPasswordModal() {
    hideLoginModal();
    $.post(FromUrl,{type:'forget_pwd',gid:gid},function(html) {
        document.getElementById('floatBall').insertAdjacentHTML('afterend', html);
    });
}

// 隐藏重置密码弹窗
function hideResetPasswordModal() {
    document.querySelector('#resetPasswordModal').remove();
    showLoginModal();
}

// 发送重置密码短信验证码
function sendResetSmsCode() {
    const phone = document.getElementById('resetPhone').value;
    if (!/^1[3-9]\d{9}$/.test(phone)) {
        layer.msg('请输入正确的手机号');
        return;
    }
    
    const data = {
        phone:phone,
        type:1,
        // verify:imageCaptcha,
        gid:gid,
        cid:cid,
    };

    $.post(sendSmsUrl,data,function(info){
        if(info.code==0) {
            layer.msg(info.msg,{time:2000});
        }else if(info.code==1){
            layer.msg(info.msg,{time:2000});
            // 发送成功后开始倒计时
            startCountdown(button);
        }else{
            // 其他错误
            layer.msg(info.msg || '发送失败，请重试', {time: 2000});
        }
    })
    const button = document.querySelector('#resetPasswordModal .suffix-btn');
    startCountdown(button);
}

// 重置密码功能
function resetPassword() {
    const phone = document.getElementById('resetPhone').value;
    const smsCode = document.getElementById('resetSmsCode').value;
    const password = document.getElementById('resetPassword').value;
    const confirmPassword = document.getElementById('resetConfirmPassword').value;
    // 表单验证
    if (!phone || !smsCode || !password || !confirmPassword) {
        layer.msg('请填写完整信息');
        return;
    }

    if (!/^1[3-9]\d{9}$/.test(phone)) {
        layer.msg('请输入正确的手机号');
        return;
    }

    if (password !== confirmPassword) {
        layer.msg('两次输入的密码不一致');
        return;
    }
    // 这里添加重置密码API调用
    const data = {
        phone:phone,
        code: smsCode,
        password:password,
        uid:uid,
        // verify:imageCaptcha,
        gid:gid,
        cid:cid
    };
    $.post(forgetPwdUrl,data,function(info){
        
        if(info.code!=1) {
            layer.msg(info.msg,{time:2000});
            return false;
        }else{
            layer.msg('密码重置成功',{time:2000});
            location.reload();
            // hideResetPasswordModal();
            // showLoginModal();
        }
    })
}
